//
//  ViewController.swift
//  1-07-数组
//
//  Created by 范英强 on 16/1/23.
//  Copyright © 2016年 范英强. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        demo5()
    }
    
    //容量
    func demo5(){
        var array: [Int] = [Int]()
        
        for i in 0..<16 {
            array.append(i)
            print("数组count:\(array.count)~数组容量:\(array.capacity)")
        }
    }
    
    
    //数组的删除
    //removeAll(keepCapacity: true) 全部删除 是否保存容量
    func demo4(){
        var array1 = ["老王","老张","老李"]
        //全部铲除
        array1.removeAll()
        array1.removeAll(keepCapacity: true)
        //删除指定元素
        array1.removeAtIndex(0)
        
    }
    
    //遍历
    //在Swift中 获取数组指定数组元素  数组[index]
    func demo3(){
        let array1 = ["老王","老张","老李"]
        //方式1:
        for var i = 0 ;i < array1.count ; i++ {
            let name = array1[i]
            print(name)
        }
        print("===============")
        
        //方法2:
        for value in array1 {
            print(value)
        }
        print("===============")
        //方式3:
        //reverse().enumerate() 倒着遍历
        for (index, value) in array1.reverse().enumerate(){
            print("数组的第\(index)元素是\(value)")
        }
    }
    
    
    //数组的合并
    func demo2(){
        let array1 = [1,2,3,4,5]
        let array2 = [6,7,8,9]
        
        let result = array1 + array2
        
        print(result)
    }
    
    //数组的定义
    //在Swift中可以直接往数组中添加整数
    //在Swift中初始化一个数组  就是
    //let 定义 不可变数组
    //var 定义 可变数组
    
    func demo1(){
        
        let array1 = [1,2,3,4,5]
        
        let array2 = ["老王","老张"]
        
        var array3: [String] = [String]()
        
        array3.append("老赵")
        
        let array4 = [1,"老王",NSValue(CGPoint:CGPoint(x: 10, y: 10))]
    }


}

